﻿$(function () {
    //初始化控件
    laydate.render({ elem: '#txtlivePtime', type: 'datetime' });
    laydate.render({ elem: '#txtilltime', type: 'datetime' });
    laydate.render({ elem: '#txtcomedTime', type: 'datetime' });
    laydate.render({ elem: '#txtdmlssopTime', type: 'datetime' });
    laydate.render({ elem: '#txtlndmlexitPtime', type: 'datetime' });
    laydate.render({ elem: '#txtlndmldieTime', type: 'datetime' });
    position();
    $("#btnSave").on("click", function () { savemr(); });
    $("#btnPrint").on("click", function () { printmr(); });
    $("#btnDel").on("click", function () { delmr(); });
    $("#btnHisback").on("click", function () { window.location.href = "/TraumaCenter/MedicalRecords/Index"; });
    $("#btnTimePath").on("click", function () { if (IsEmpty($("#txtPatientId").val())) retrun; window.location.href = "/TraumaCenter/MedicalRecords/Timeline?pid=" + $("#txtPatientId").val(); });
    SetValue();
    $(":text[typeof=number]").keyup(function () {
        var c = $(this);
        if (/[^\d]/.test(c.val())) {
            var num = c.val().replace(/[^\d]/g, '');
            $(this).val(num == "" ? "" : parseInt(num));
        }
    });
    $('input[name="rdocomeinismRs"]').click(function () {
        if ($("input[name='rdocomeinismRs']:checked").val() == 1) {
            $("#rdocomeinismRsYes").show();
        } else {
            $("#rdocomeinismRsYes").hide();
        }
    });
    $('input[name="rdocomeinisNihss"]').click(function () {
        if ($("input[name='rdocomeinisNihss']:checked").val() == 1) {
            $("#rdocomeinisNihssYes").show();
        } else {
            $("#rdocomeinisNihssYes").hide();
        }
    });
    $('input[name="rdocomeinisGcs"]').click(function () {
        if ($("input[name='rdocomeinisGcs']:checked").val() == 1) {
            $("#rdocomeinisGcsYes").show();
        } else {
            $("#rdocomeinisGcsYes").hide();
        }
    });
    $('input[name="rdocomeinisHH"]').click(function () {
        if ($("input[name='rdocomeinisHH']:checked").val() == 1) {
            $("#rdocomeinisHHYes").show();
        } else {
            $("#rdocomeinisHHYes").hide();
        }
    });
    $('input[name="rdocomeinisFisher"]').click(function () {
        if ($("input[name='rdocomeinisFisher']:checked").val() == 1) {
            $("#rdocomeinisFisherYes").show();
        } else {
            $("#rdocomeinisFisherYes").hide();
        }
    });
    $('input[name="rdoisjbsingbfz"]').click(function () {
        if ($("input[name='rdoisjbsingbfz']:checked").val() == 1) {
            $("#rdoisjbsingbfzYes").show();
        } else {
            $("#rdoisjbsingbfzYes").hide();
        }
    });
    $('input[name="rdoishavethq"]').click(function () {
        if ($("input[name='rdoishavethq']:checked").val() == 1) {
            $("#rdoishavethqYes").show();
        } else {
            $("#rdoishavethqYes").hide();
        }
    });
    $('input[name="rdoishavezj"]').click(function () {
        if ($("input[name='rdoishavezj']:checked").val() == 1) {
            $("#rdoishavezjYes").show();
        } else {
            $("#rdoishavezjYes").hide();
        }
    });
    $('input[name="rdossopqn"]').click(function () {
        if ($("input[name='rdossopqn']:checked").val() == 1) {
            $("#rdossopqnYes").show();
        } else {
            $("#rdossopqnYes").hide();
        }
    });
    $('input[name="rdoishavesssingbfz"]').click(function () {
        if ($("input[name='rdoishavesssingbfz']:checked").val() == 1) {
            $("#rdoishavesssingbfzYes td").show();
        } else {
            $("#rdoishavesssingbfzYes td").hide();
        }
    });
    $('input[name="rdolndmliskfzl"]').click(function () {
        if ($("input[name='rdolndmliskfzl']:checked").val() == 1) {
            $("#rdolndmliskfzlYes1 td,#rdolndmliskfzlYes2 td").show();
        } else {
            $("#rdolndmliskfzlYes1 td,#rdolndmliskfzlYes2 td").hide();
        }
    });
    $('input[name="rdolndmlheathisxj"]').click(function () {
        if ($("input[name='rdolndmlheathisxj']:checked").val() == 1) {
            $("#rdolndmlheathisxjYes").show();
        } else {
            $("#rdolndmlheathisxjYes").hide();
        }
    });
    $('input[name="rdolndmlexitPType"]').click(function () {
        if ($("input[name='rdolndmlexitPType']:checked").val() == 4) {
            $("#rdolndmlexitPTypeYes1,#rdolndmlexitPTypeYes2").show();
        } else {
            $("#rdolndmlexitPTypeYes1,#rdolndmlexitPTypeYes2").hide();
        }
    });
    $('input[name="rdolndmlleavehospismRs"]').click(function () {
        if ($("input[name='rdolndmlleavehospismRs']:checked").val() == 1) {
            $("#rdolndmlleavehospismRsYes").show();
        } else {
            $("#rdolndmlleavehospismRsYes").hide();
        }
    });
    $('input[name="rdolndmlexitisNihss"]').click(function () {
        if ($("input[name='rdolndmlexitisNihss']:checked").val() == 1) {
            $("#rdolndmlexitisNihssYes").show();
        } else {
            $("#rdolndmlexitisNihssYes").hide();
        }
    });
    $('input[name="rdolndmlexitisGcs"]').click(function () {
        if ($("input[name='rdolndmlexitisGcs']:checked").val() == 1) {
            $("#rdolndmlexitisGcsYes").show();
        } else {
            $("#rdolndmlexitisGcsYes").hide();
        }
    });
});
function position() {
    LiftEffect({
        "control1": ".lift-nav",
        "control2": ".lift",
        "target": [".t0", ".t1", ".t2", ".t3", ".t4", ".t5", ".t6"],
        "current": "current"
    });
}
function printmr() {
    if ($("#txtPatientId").val() == "") return;
    window.parent.top.tab.addTabItem({ tabid: "print" + $("#txtPatientId").val(), text: "病历-" + $("#txtrealName").val(), url: "/TraumaCenter/MedicalRecords/LndmlmrPrint?pid=" + $("#txtPatientId").val() });
}
function delmr() {
    if ($("#txtPatientId").val() == "") return;
    $.ligerDialog.confirm('确定删除该患者吗', function (yes) {
        if (yes) {
            var url = "/TraumaCenter/PatientList/GiveUp";
            $.get(url, {
                rnd: new Date().getMilliseconds(),
                patientId: $("#txtPatientId").val()
            }, function (data, textStatus) {
                if (textStatus == "success") {
                    var d = $.parseJSON(data);
                    if (d.Result == 1) {
                        search(1);
                        $.ligerDialog.success("操作成功");
                    }
                    else if (d.Result == 0) {
                        $.ligerDialog.error(d.Body);
                    }
                    else {
                        $.ligerDialog.error("程序错误");
                    }
                }
            })
        }
    });
}
function savemr() {
    if ($("#txtPatientId").val() == "") return;
    var data = {};
    $.each(FiledArray, function (i, a) {
        var datadetail = {};
        $.each(a.column, function (j, b) {
            var str = "";
            if (b.type == "text" || b.type == 'date') {
                str = $('#' + b.code).val();
            } else if (b.type == "radio") {
                str = $("input[name='" + b.code + "']:checked").val();
            } else if (b.type == "checkbox") {
                var str = CheckBoxToArrStr(b.code);
            }
            datadetail[b.tocode] = str == "" ? b.value : str;
        })
        data[a.table] = datadetail;
    })
    $.post("/TraumaCenter/MedicalRecords/SaveLndmlmr", { datajson: JSON.stringify(data), rd: Math.random() }, function (data, textStatus) {
        if (textStatus == "success") {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                $.ligerDialog.success("保存成功");
            }
            else if (d.Result == 0) {
                $.ligerDialog.error(d.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        }
    })
}
function SetValue() {
    var patientid = $('#txtPatientId').val();
    if (Number(patientid) > 0) {
        $.ajax({
            url: '/TraumaCenter/MedicalRecords/Get_IntracranialAneurysm?patientid=' + patientid + '&ram=' + Math.random(),
            cache: false,
            dataType: 'json',
            success: function (data) {
                $.each(FiledArray, function (i, a) {
                    var datadetail = eval("data." + a.table);
                    if (datadetail != undefined && datadetail != null) {
                        $.each(a.column, function (j, b) {
                            if (b.type == "text") {
                                $('#' + b.code).val(eval("datadetail." + b.tocode));
                            } else if (b.type == "date") {
                                $('#' + b.code).val(obj2Timemm(eval("datadetail." + b.tocode)));
                            } else if (b.type == "radio") {
                                $("input[name='" + b.code + "'][value='" + eval("datadetail." + b.tocode) + "']").attr("checked", true);
                                $("input[name='" + b.code + "'][value='" + eval("datadetail." + b.tocode) + "']").click();
                            } else if (b.type == "checkbox") {
                                CheckBoxSetVal(b.code, eval("datadetail." + b.tocode));
                            }
                        })
                    }
                })
            }
        });
    } else {
        $.ligerDialog.error("获取数据失败！");
    }
}
var FiledArray = [
    {
        table: "patientInfo",
        column: [
            { name: "ID", code: "txtPIId", tocode: "ID", value: "0", type: "text" },
            { name: "姓名", code: "txtrealName", tocode: "PATIENT_NAME", value: "", type: "text" },
            { name: "性别", code: "rdogender", tocode: "PATIENT_SEX", value: "", type: "radio" },
            { name: "身份证", code: "txtIDcard", tocode: "PATIENT_ID_NUM", value: "", type: "text" },
            { name: "住院号", code: "txtlivePid", tocode: "PatCardNO", value: "", type: "text" },
            { name: "病案号", code: "txtpataId", tocode: "PATIENT_ID", value: "", type: "text" },
            { name: "病人编号", code: "txtpatId", tocode: "PATIENT_ID", value: "", type: "text" },
            { name: "来院方式", code: "rdocomeType", tocode: "PATIENT_ARRIVE_CLASS", value: "", type: "radio" }
        ]
    },
    {
        table: "ambulanceInfo",
        column: [
            { name: "ID", code: "txtAIId", tocode: "ID", value: "0", type: "text" },
            { name: "txtpatId", code: "txtpatId", tocode: "PATIENT_ID", value: "", type: "text" },
            { name: "发病时间", code: "txtilltime", tocode: "EMS_DISEASE_TIME", value: "", type: "date" },
            { name: "住院时间", code: "txtlivePtime", tocode: "AdmissionTime", value: "", type: "date" },
            { name: "到院时间", code: "txtcomedTime", tocode: "EMS_ARRIVEDOOR_TIME", value: "", type: "date" },
            { name: "入院途径", code: "rdocomeinType", tocode: "AdmissionPath", value: "", type: "radio" }
        ]
    },
    {
        table: "patientIAMR",
        column: [
            { name: "ID", code: "txtPCId", tocode: "ID", value: "0", type: "text" },
            { name: "txtpatId", code: "txtpatId", tocode: "Patient_ID", value: "", type: "text" },
            { name: "发病", code: "rdoillshow", tocode: "Base_AIS_Type", value: "0", type: "radio" },
            { name: "是否在院创伤", code: "rdoisinhospill", tocode: "Base_AIS_Hospital", value: "0", type: "radio" },
            { name: "动脉瘤临床分类", code: "rdodmllcType", tocode: "Assessment_Aneurysm_Type", value: "0", type: "radio" },
            { name: "既往动脉瘤破裂史", code: "rdoywjwdmlpls", tocode: "Assessment_AneurysmRupture_Bool", value: "0", type: "radio" },
            { name: "入院mRS评分", code: "rdocomeinismRs", tocode: "Assessment_MRS_Bool", value: "0", type: "radio" },
            { name: "评分分数", code: "txtcomeinmRs", tocode: "Assessment_MRS_Score", value: "", type: "text" },
            { name: "入院NIHSS评分", code: "rdocomeinisNihss", tocode: "Assessment_Nihss_Bool", value: "0", type: "radio" },
            { name: "评分分数", code: "txtcomeinNihss", tocode: "Assessment_Nihss_Score", value: "", type: "text" },
            { name: "GCS评分", code: "rdocomeinisGcs", tocode: "Assessment_Gcs_Bool", value: "0", type: "radio" },
            { name: "评分分数", code: "txtcomeinGcs", tocode: "Assessment_Gcs_Score", value: "", type: "text" },
            { name: "Hunt-Hess分级", code: "rdocomeinisHH", tocode: "Assessment_HuntHess_Bool", value: "0", type: "radio" },
            { name: "分级", code: "txtcomeinHH", tocode: "Assessment_HuntHess_Score", value: "", type: "text" },
            { name: "Fisher 分级", code: "rdocomeinisFisher", tocode: "Assessment_Fisher_Bool", value: "0", type: "radio" },
            { name: "分级", code: "txtcomeinFisher", tocode: "Assessment_Fisher_Score", value: "", type: "text" },
            { name: "是否脑疝", code: "rdocomeinisNs", tocode: "Assessment_CerebralHernia_Bool", value: "0", type: "radio" },
            { name: "尼莫地平预防血管痉挛治疗", code: "rdocomeinisNmdpyfxgjlzl", tocode: "Assessment_Nimodipine_Bool", value: "0", type: "radio" },
            { name: "颅内血管检查方式", code: "cbxlnxgChkType", tocode: "Image_Check_Style", value: "", type: "checkbox" },
            { name: "动脉瘤数量", code: "txtdmlCount", tocode: "Image_Aneurysm_Num", value: "", type: "text" },

            { name: "左侧", code: "cbxdmlzrxgbodyareal", tocode: "Image_Aneurysm_AdressLeft", value: "", type: "checkbox" },
            { name: "长", code: "txtdmlzrxgbaLength", tocode: "Image_Aneurysm_LengthLeft", value: "", type: "text" },
            { name: "宽", code: "txtdmlzrxgbaLWeith", tocode: "Image_Aneurysm_WidthLeft", value: "", type: "text" },
            { name: "高", code: "txtdmlzrxgbaLHeigh", tocode: "Image_Aneurysm_HeighLeft", value: "", type: "text" },
            { name: "瘤颈", code: "txtdmlzrxgbaLlj", tocode: "Image_Tumor_NeckeftLeft", value: "", type: "text" },
            { name: "类型", code: "rdodmlzrxgbaLType", tocode: "Image_Tumor_TypeeftLeft", value: "0", type: "radio" },
            { name: "部位", code: "rdodmlzrxgbaLinfo", tocode: "Image_Tumor_PartseftLeft", value: "0", type: "radio" },

            { name: "右侧", code: "cbxdmlzrxgbodyarear", tocode: "Image_Aneurysm_AdressRight", value: "", type: "checkbox" },
            { name: "长", code: "txtdmlzrxgbaRength", tocode: "Image_Aneurysm_LengthRight", value: "", type: "text" },
            { name: "宽", code: "txtdmlzrxgbaRWeith", tocode: "Image_Aneurysm_WidthRight", value: "", type: "text" },
            { name: "高", code: "txtdmlzrxgbaRHeigh", tocode: "Image_Aneurysm_HeighRight", value: "", type: "text" },
            { name: "瘤颈", code: "txtdmlzrxgbaRlj", tocode: "Image_Tumor_NeckeftRight", value: "", type: "text" },
            { name: "类型", code: "rdodmlzrxgbaRType", tocode: "Image_Tumor_TypeeftRight", value: "0", type: "radio" },
            { name: "部位", code: "rdodmlzrxgbaRinfo", tocode: "Image_Tumor_PartseftRight", value: "0", type: "radio" },

            { name: "手术类型", code: "rdodmlssopType", tocode: "Surgery_Style", value: "0", type: "radio" },
            { name: "手术时间", code: "txtdmlssopTime", tocode: "Surgery_Time", value: "", type: "date" },
            { name: "动脉瘤治疗结果", code: "rdodmlzlres", tocode: "Surgery_Clipping_Results", value: "0", type: "radio" },
            { name: "夹闭后载瘤动脉情况", code: "rdojbhzldmqk", tocode: "Surgery_Clipping_Situation", value: "0", type: "radio" },
            { name: "夹闭术过程中并发症", code: "rdoisjbsingbfz", tocode: "Surgery_Clipping_ComplicationsBool", value: "0", type: "radio" },
            { name: "并发症", code: "cbxjbsingbfz", tocode: "Surgery_Clipping_ComplicationsType", value: "", type: "checkbox" },
            { name: "介入途径", code: "cbxjrsss", tocode: "Embolotherapy_Way_Type", value: "", type: "checkbox" },
            { name: "弹簧圈", code: "rdoishavethq", tocode: "Embolotherapy_SpringCoil_Bool", value: "0", type: "radio" },
            { name: "个数", code: "txtthqCount", tocode: "Embolotherapy_SpringCoil_Num", value: "", type: "text" },
            { name: "支架", code: "rdoishavezj", tocode: "Embolotherapy_Stents_Bool", value: "0", type: "radio" },
            { name: "支架名称", code: "cbxssopzjName", tocode: "Embolotherapy_Stents_Type", value: "", type: "checkbox" },
            { name: "球囊", code: "rdossopqn", tocode: "Embolotherapy_Balloon_Bool", value: "0", type: "radio" },
            { name: "个数", code: "txtssopqnCount", tocode: "Embolotherapy_Balloon_Num", value: "", type: "text" },
            { name: "其他栓塞材料", code: "cbxssopothersscl", tocode: "Embolotherapy_OtherMaterial", value: "", type: "checkbox" },
            { name: "动脉瘤治疗结果", code: "rdossopdmlzlres", tocode: "Embolotherapy_Results", value: "0", type: "radio" },
            { name: "载瘤动脉情况", code: "rdossopzldmqk", tocode: "Embolotherapy_Situation", value: "0", type: "radio" },
            { name: "栓塞术过程中并发症", code: "rdoishavesssingbfz", tocode: "Embolotherapy_Clipping_ComplicationsBool", value: "0", type: "radio" },
            { name: "并发症", code: "cbxsssingbfz", tocode: "Embolotherapy_Clipping_ComplicationsType", value: "", type: "checkbox" },
            { name: "接受康复治疗", code: "rdolndmliskfzl", tocode: "Rehabilitation_Treatment_Bool", value: "0", type: "radio" },
            { name: "康复治疗方式", code: "cbxlndmlkfzlType", tocode: "Rehabilitation_Treatment_Type", value: "", type: "checkbox" },
            { name: "康复治疗场所", code: "cbxlndmlkfzlAddr", tocode: "Rehabilitation_Treatment_Adress", value: "", type: "checkbox" },
            { name: "健康宣教", code: "rdolndmlheathisxj", tocode: "Health_Education_Bool", value: "0", type: "radio" },
            { name: "宣教方式", code: "cbxlndmlheathxjType", tocode: "Health_Education_Type", value: "", type: "checkbox" },
            { name: "出院时间", code: "txtlndmlexitPtime", tocode: "Hospital_Out_Time", value: "", type: "date" },
            { name: "离院方式", code: "rdolndmlexitPType", tocode: "Hospital_Out_Type", value: "0", type: "radio" },
            { name: "死亡时间", code: "txtlndmldieTime", tocode: "Death_Time", value: "", type: "date" },
            { name: "死亡原因", code: "cbxlndmldieReason", tocode: "Death_Why", value: "", type: "checkbox" },
            { name: "出院时mRS评分", code: "rdolndmlleavehospismRs", tocode: "Hospital_MRS_Bool", value: "0", type: "radio" },
            { name: "评分", code: "txtlndmlleavehospmRs", tocode: "Hospital_MRS_Score", value: "", type: "text" },
            { name: "出院NIHSS评分", code: "rdolndmlexitisNihss", tocode: "Hospital_Nihss_Bool", value: "0", type: "radio" },
            { name: "评分", code: "txtlndmlleavehospNihss", tocode: "Hospital_Nihss_Score", value: "", type: "text" },
            { name: "出院时GCS评分", code: "rdolndmlexitisGcs", tocode: "Hospital_GCS_Bool", value: "0", type: "radio" },
            { name: "评分", code: "txtlndmlexitGcs", tocode: "Hospital_GCS_Score", value: "", type: "text" },
            { name: "出院带药", code: "cbxlndmlexitpwithy", tocode: "Hospital_Drug_Bool", value: "", type: "checkbox" }
        ]
    },
    {
        table: "patientSigns",
        column: [
            { name: "ID", code: "txtPSId", tocode: "PATIENT_SIGNS_ID", value: "0", type: "text" },
            { name: "txtpatId", code: "txtpatId", tocode: "PATIENT_ID", value: "", type: "text" },
            { name: "民族", code: "txtethnic", tocode: "Patient_National", value: "", type: "text" },
            { name: "医疗付款方式", code: "chkmedicalinsurance", tocode: "Patient_Pay_Type", value: "", type: "radio" },
            { name: "住院次数", code: "txtlivePcount", tocode: "Patient_Hospital_Num", value: "", type: "text" },
            { name: "BMI(kg/㎡)", code: "txtbmiVal", tocode: "Patient_BMI", value: "", type: "text" },
            { name: "脉搏(次/分)", code: "txtpmbVal", tocode: "PATIENT_HEART", value: "", type: "text" },
            { name: "收缩压(mmHg)", code: "txtpssyVal", tocode: "PATIENT_BLOOD_H", value: "", type: "text" },
            { name: "舒张压(mmHg)", code: "txtpszyVal", tocode: "PATIENT_BLOOD_L", value: "", type: "text" },
            { name: "身高(cm)", code: "txtpheigh", tocode: "Patient_Height", value: "", type: "text" },
            { name: "体重(kg)", code: "txtpweight", tocode: "Patient_Weight", value: "", type: "text" }
        ]
    }
]
